package logic

import (
	"context"
	"hzjt-oam/rpc/sys/internal/svc"
	"hzjt-oam/rpc/sys/model"
	"hzjt-oam/rpc/sys/pb"
	"time"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddSysDeptLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddSysDeptLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddSysDeptLogic {
	return &AddSysDeptLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// -----------------------机构管理-----------------------
func (l *AddSysDeptLogic) AddSysDept(in *pb.AddSysDeptReq) (*pb.AddSysDeptResp, error) {
	var sys_dept = &model.SysDept{
		Name:           in.Name,
		CreateBy:       in.CreateBy,
		CreateTime:     time.Now().Unix(),
		LastUpdateBy:   in.CreateBy,
		LastUpdateTime: time.Now().Unix(),
		DelFlag:        0,
	}
	_, err := l.svcCtx.DeptModel.Insert(l.ctx, sys_dept)

	if err != nil {
		return nil, err
	}

	return &pb.AddSysDeptResp{}, nil
}
